package com.hk.manage.login.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hk.commons.redis.RedisUtil;
import com.hk.commons.utils.BeanConvertUtil;
import com.hk.commons.vo.ExecuteResult;
import com.hk.dao.manage.user.mapper.ManagerUserMapper;
import com.hk.dao.manage.user.model.ManagerUserDO;
import com.hk.dao.manage.user.qo.ManagerUserPageQO;
import com.hk.manage.constant.RedisKeysConstant;
import com.hk.manage.login.async.MangerLoginAsync;
import com.hk.manage.login.excel.ManagerUserExport;
import com.hk.manage.login.service.ManagerLoginService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ManagerLoginServiceImpl implements ManagerLoginService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ManagerLoginServiceImpl.class);

    @Resource
    private MangerLoginAsync mangerLoginAsync;

    @Resource
    private ManagerUserMapper mapper;

    @Resource
    private RedisUtil redisUtil;




    @Override
    public ExecuteResult<String> redis() {
        String key = RedisKeysConstant.MANAGE_LOGIN_PREFIX + "123";
        redisUtil.setString(key,"123",100L);
        String stringValue = (String) redisUtil.getValue(key);
        ManagerUserDO managerUserDO = new ManagerUserDO();
        managerUserDO.setId(111L);
        redisUtil.setObj("user",managerUserDO,100L);

        ManagerUserDO object =  redisUtil.getObj("user",ManagerUserDO.class);
        return new ExecuteResult<>(stringValue);
    }

    @Override
    public ExecuteResult<List<ManagerUserExport>> getAll() {
        List<ManagerUserDO> list = mapper.getAll();
        if (list.isEmpty()){
            return null;
        }
        List<ManagerUserExport> managerUserExports = new ArrayList<>();
        list.forEach(managerUserDO -> {
            ManagerUserExport managerUserExport = BeanConvertUtil.copyObj(managerUserDO, ManagerUserExport.class);
            managerUserExports.add(managerUserExport);
        });
        return new ExecuteResult<>(managerUserExports);
    }

    @Override
    public ExecuteResult<PageInfo<ManagerUserDO>> listPage(ManagerUserPageQO qo) {
        PageHelper.startPage(qo.getPageNum(),qo.getPageSize());
        List<ManagerUserDO> user = mapper.queryListPage(qo);
        PageInfo<ManagerUserDO> pageInfo = new PageInfo<>(user);
        return new ExecuteResult<>(pageInfo);
    }


}
